package com.loong.game2048.module;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author lyx
 * @date 2020/5/5 11:20
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Tile {
    private boolean merged;
    private int value;
    //构造方法
    Tile(int val) {
        value = val;
    }


    //判断能否合并
    boolean canMergeWith(Tile other) {
        //本身、other的merged标记都为flase,且值相同，才能合并
        return !merged && other != null && !other.merged && value == other.getValue();
    }

    //合并
    int mergeWith(Tile other) {
        if (canMergeWith(other)) {
            value *= 2;
            merged = true;
            return value;
        }
        return -1;
    }

}
